<template>
  <!-- 系统设置页面 -->
  <div class="artist-data">
    <el-card
      class="table-card header_boder_bottom artist_tabel_box"
      shadow="never"
    >
      <!-- 列表搜索 -->
      <div class="sreach-box">
        <Add ref="addDrama" style="height: 32px" @close="closeAdd"></Add>
      </div>

      <div v-if="data" v-loading="tableLoading" class="tab_box">
        <XgmTable
          ref="artistTable"
          :columns.sync="columnsShow"
          :data="
            data.slice(
              (pagination.page - 1) * pagination.pageSize,
              pagination.page * pagination.pageSize
            )
          "
          @selectionChange="selectionChange"
          @sortChange="sortChange"
        >
          <!-- 高亮表头 -->
          <template
            v-for="(prop, i) in redTable"
            :slot="`header-${prop}`"
            slot-scope="{ label }"
          >
            <span :key="i">
              <span style="color: red">{{ label }}</span>
            </span>
          </template>

          <template slot="is_admin" slot-scope="{ scope }">
            <el-tag v-if="scope.row.is_admin" type="success">管理员</el-tag>
            <el-tag v-else type="warning">非管理员</el-tag>
          </template>

          <template slot="edit" slot-scope="{ scope }">
            <div class="edit-box">
              <el-button
                type="primary"
                class="bg-6BD9BA"
                @click="editR(scope.row)"
              >
                修改
              </el-button>
              <el-button
                type="danger"
                class="bg-6BD9BA"
                @click="deleteR(scope.row)"
              >
                删除
              </el-button>
            </div>
          </template>
        </XgmTable>
      </div>
    </el-card>
    <div class="page-footer">
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="pagination.page"
        :page-size="pagination.pageSize"
        :page-sizes="pagination.pageSizeS"
        :total="pagination.total"
        @current-change="onCurrentChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
let columns = [
  {
    label: '用户名',
    prop: 'username',
    width: 'auto',
    showOverflowTooltip: false,
  },
  {
    label: '是否是管理员',
    prop: 'is_admin',
    width: 'auto',
    showOverflowTooltip: true,
  },
  {
    label: '操作',
    prop: 'edit',
    fixed: 'right',
    width: '140',
    showOverflowTooltip: true,
  },
]
import { adminList, deleteAdmin } from '@/api/admin.js'
import XgmTable from '@/components/XgmTable'
import Add from './components/add.vue'
export default {
  name: 'RecommendList',
  components: { XgmTable, Add },
  props: {},
  data() {
    return {
      data: [],
      ReplaceEnum: [],
      type_list: [
        { id: 1, name: '增加' },
        { id: -1, name: '减少' },
      ],
      columns,
      redTable: [],
      pagination: {
        total: 0,
        page: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeS: [10, 20, 40],
        showTotal: (total) => `共有 ${total} 条数据`,
      },
      search_queryParam: { nick_name: '', user_id: '' },
      else_queryParam: {
        create_time: '',
        type: '',
        source: '',
        start_time: '',
        end_time: '',
      },
      sort: {
        order_type: 'desc', // 'desc ,
        order_key: 'update_time',
      },
      tableLoading: false,
      searchType: 'user_id',
      searchText: '',
    }
  },
  computed: {
    columnsShow: {
      get() {
        return this.columns
      },
      set(val) {
        this.exportColumns = val.filter((item) => item.prop != 'edit')
      },
    },
  },
  watch: {},
  async created() {
    // 列表
    this.getAdminList()
  },
  methods: {
    async getAdminList() {
      this.tableLoading = false
      let data = await adminList()
      if (data.code == 200) {
        this.pagination = Object.assign(this.pagination, {
          total: data.users.length,
        })
        this.data = data.users
      }
      this.tableLoading = false
    },
    onCurrentChange(e) {
      this.pagination.page = e
    },

    async deleteR(item) {
      let data = await deleteAdmin(item.username)
      if (data.code == 200) {
        this.$baseMessage('操作成功', 'success')
        setTimeout(() => {
          this.getAdminList()
        }, 500)
      }
    },
    editR(row) {
      this.$refs.addDrama.applynewadd(row)
    },
    closeAdd(e) {
      if (e) {
        this.getAdminList()
      }
    },
    emptsearch() {
      this.searchText = ''
      Object.assign(this.else_queryParam, this.$options.data().else_queryParam)
      Object.assign(
        this.search_queryParam,
        this.$options.data().search_queryParam
      )
    },

    selectionChange(selection) {
      this.seltTableData = selection
    },

    // 排序 order是降序或者升序 prop是字段
    sortChange({ order, prop }) {
      this.sort.order_type = {
        ascending: 'asc',
        descending: 'desc',
      }[order]
      this.sort.order_key = prop
      this.pagination.page = 1
      this.getAdminList()
    },
  },
}
</script>
<style lang="scss" scoped>
.df {
  display: flex;
  align-items: center;
}

.edit-box {
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-footer {
  position: sticky;
  bottom: 0;
  padding: 0 14px 14px;
  background-color: #fff;
  z-index: 10;
}

p {
  margin-bottom: 0;
}

.contract-tip-box {
  width: 150px;
  word-break: break-all;

  > p {
    margin-bottom: 4px;
    font-size: 12px;
  }
}

.account-user-box {
  display: flex;
  justify-content: space-between;
  word-break: break-all;
  background-color: #fff;
  padding: 14px 10px;
  border-radius: 10px;
  overflow: hidden;

  .head_img_box {
    position: relative;
    width: 40px;
    height: 40px;
    overflow: hidden;

    .head_img {
      width: 100%;
      height: 100%;
      border-radius: 40px;
    }

    .platform_path {
      position: absolute;
      bottom: -6px;
      right: 0;
      width: 14px;
    }
  }

  .user-text {
    margin-left: 10px;
    flex: 1;

    p {
      font-size: 12px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333333;
      line-height: 17px;

      display: flex;
      justify-content: space-between;
      margin-bottom: 6px;
    }

    .anchor_name {
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #2a304d;
      line-height: 20px;
    }

    .anchor_id {
      font-size: 12px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #8895a4;
      line-height: 17px;
      margin-bottom: 8px;
    }
  }
}

.acc_msg {
  display: flex;

  .account-table-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 10px;
    grid-row: 10px;

    .account-box {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100px;

      .account-item {
        color: #3f8cff;
        font-size: 14px;
        padding: 2px 12px;
        line-height: 20px;
        white-space: nowrap;
        display: inline-block;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;

        background: #f1f7ff;
        border-radius: 2px;
        border: 1px solid #3a90ff;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
      }
    }
  }
}

.artist-data {
  padding: 10px 10px 0;
  min-height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;

  ::v-deep.ant-spin-nested-loading {
    background-color: #fff;
    flex: 1;
  }

  p {
    margin-bottom: 0;
  }

  .sreach-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    border-radius: 5px;
    margin-bottom: 20px;

    .line {
      background: #dfdfe1;
      width: 1px;
      height: 30px;
      display: inline-block;
    }

    > p {
      font-size: 14px;
      color: #333333;
    }
  }

  .screen-box {
    background-color: white;
    padding: 20px 15px 0px 15px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    .screen-left-box {
      flex: 1;
    }

    .item {
      display: flex;
      align-items: flex-start;
      padding-bottom: 16px;

      &:last-child {
        padding-bottom: 0px;
      }

      .tag-box {
        display: flex;
        align-items: center;
        flex-wrap: wrap;

        .screen-tag {
          cursor: pointer;
          line-height: 22px;
          padding: 0 9px;
          margin-right: 10px;
          color: #333333;
          border-radius: 2px;
          margin-bottom: 4px;

          font-size: 12px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;

          &:hover {
            background-color: #deeafe;
            color: #333333;
          }
        }

        .screen-tag-blue {
          line-height: 17px;
          padding: 2px 9px;
          margin-right: 10px;
          color: #3f8cff;
          border: 1px solid #3f8cff;
          font-size: 14px;
          border-radius: 2px;
          display: flex;
          background-color: #f1f7ff;
          align-items: center;
          margin-bottom: 5px;

          .delete-icon {
            cursor: pointer;
            width: 11px;
            height: 11px;
            border-radius: 50%;
            background: #72b1f0;
            text-align: center;
            line-height: 9px;
            font-size: 10px;
            color: #fff;
            transform: scale(0.9);
            margin-left: 5px;

            &:hover {
              background: #2292ec;
              color: #fff;
            }
          }
        }

        .add-economy {
          cursor: pointer;
          line-height: 17px;
          padding: 2px 9px;
          margin-right: 30px;
          color: #3f8cff;
          border: 1px dashed #3f8cff;
          font-size: 14px;
          border-radius: 2px;
          display: flex;
          align-items: center;
          font-weight: bold;
          margin-bottom: 5px;

          &:hover {
            background-color: #f1f7ff;
          }
        }

        .screen-tag-active {
          background: #3a90ff !important;
          color: #fff !important;
        }
      }
    }

    .item-name {
      min-width: 80px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333333;
      line-height: 20px;
    }

    .more-screen-box {
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      color: #3a90ff;
      font-size: 14px;
      margin-left: 10px;

      img {
        width: 20px;
        height: 20px;
        margin-right: 3px;
      }
    }
  }

  .artist-table {
    ::v-deep.el-checkbox .el-checkbox__inner {
      border-radius: 4px;
    }

    ::v-deep.el-table-column--selection .cell {
      padding-left: 14px;
    }
  }

  .footer-edit-btns {
    float: left;
    padding: 14px 0;
    display: flex;

    & > * {
      margin-right: 10px;
    }
  }

  ::v-deep.table-card {
    margin-top: 0;
    border: none;
    border-radius: 0;
  }
}

.right-search-body {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.upload-list-inline ::v-deep .ant-upload-list-item {
  float: left;
  width: 200px;
  margin-right: 8px;
}

.upload-list-inline ::v-deep .ant-upload-animate-enter {
  animation-name: uploadAnimateInlineIn;
}

.upload-list-inline ::v-deep .ant-upload-animate-leave {
  animation-name: uploadAnimateInlineOut;
}

.ywk ::v-deep .ant-upload-list {
  display: none !important;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
  font-variant: tabular-nums;
  line-height: 1.5;
  list-style: none;
  font-feature-settings: 'tnum';
  zoom: 1;
}

.ywk1 ::v-deep .el-input__inner {
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #d9d9d9;
  box-sizing: border-box;
  color: #333;
  display: inline-block;
  font-size: inherit;
  height: 30px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
}

.ywk {
  width: 370px;
}

.ywk ::v-deep .el-form-item__label {
  width: 130px !important;
}

/* .el-range__icon {
    display: none;
  } */
/* .ywk  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 15px;
}
 .ywk2  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 15px;
} */
/* .ywk ::v-deep.el-input__prefix, .el-input__suffix {
    top: 0;
    height: 100%;
    color: #C0C4CC;
    text-align: right;
    right: 0px !important
}
.ywk2 ::v-deep.el-input__prefix, .el-input__suffix {
    position: absolute !important;
    top: -1;
    height: 100%;
    color: #C0C4CC;
    text-align: right;
    right: 0px !important
} */
// .add_btn {
//   margin-bottom: 10px;
//   background: #6bd9ba;
//   border: none;
// }
// .add_btn:hover {
//   background: #20ae71;
// }
/* .visab_hidden{
    position: fixed;
    z-index: -999;
} */
</style>

<style lang="scss">
.account-table-popover {
  background-color: #fff;
  padding: 0 !important;
}
</style>
